/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VistaEmpleado.java
 *
 * Created on 15/10/2011, 08:52:50 AM
 */

package Vistas;

import Beans.Cargo;
import Beans.Ciudad;
import Beans.Empleado;
import Beans.Pais;
import Beans.Provincia;
import Beans.Ubicacion;
import Beans.Usuario;
import Controladores.MCargo;
import Controladores.MEmpleado;
import Controladores.MUbicacion;
import Imagenes.CtrlImagen;
import java.awt.Image;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Ryodans
 */
public class VistaEmpleado extends javax.swing.JFrame {

    /** Creates new form VistaEmpleado */
    DefaultTableModel dtm = new DefaultTableModel();
    MEmpleado Me = new MEmpleado();
    MCargo Mc =new  MCargo();
    MUbicacion Mu = new MUbicacion();
    Vector<Empleado> vc = new Vector<Empleado>();

    Cargo ca = new Cargo();
    int fila;
    boolean condicion = false; 
    Empleado e = new Empleado();

    public VistaEmpleado() {
        initComponents();
    }

    public VistaEmpleado(MEmpleado Me,MCargo Mc,MUbicacion Mu) {
        initComponents();
        this.Mc = Mc;
        this.Me = Me;
        this.Mu = Mu;
        this.DesactivarCampos();
        this.setResizable(false);
        this.TablaPrincipal();
        this.JcomboCargos();
        this.jComboPais();


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new CtrlImagen("/Imagenes/a1.jpg");
        jPanelTransparente6 = new Imagenes.JPanelTransparente();
        jCBCiudad = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTxaObs = new javax.swing.JTextArea();
        jLabel10 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jTxtNombre = new javax.swing.JTextField();
        jTcedula = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jCbxPais = new javax.swing.JComboBox();
        jLabel17 = new javax.swing.JLabel();
        jCbxProvincia = new javax.swing.JComboBox();
        jLabel19 = new javax.swing.JLabel();
        jLblFoto = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jBtnFoto = new javax.swing.JButton();
        jTxtCelular = new javax.swing.JTextField();
        jTxtTelefono = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jTxtMail = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jTxDireccion = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jButton9 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jTxtApellido = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jCBCargo = new javax.swing.JComboBox();
        jPanelTransparente7 = new Imagenes.JPanelTransparente();
        jBSalir1 = new javax.swing.JButton();
        jBActualizar = new javax.swing.JButton();
        jBModificar = new javax.swing.JButton();
        jBEliminar = new javax.swing.JButton();
        jBRegistrar = new javax.swing.JButton();
        JBuscar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Interfaz Control de Articulos");
        setBackground(new java.awt.Color(255, 255, 255));

        jTxaObs.setColumns(20);
        jTxaObs.setRows(5);
        jScrollPane1.setViewportView(jTxaObs);

        jLabel10.setText("Nº Telefono:");

        jLabel12.setText("*Cedula");

        jLabel13.setText("* Nombre:");

        jTxtNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtNombreActionPerformed(evt);
            }
        });

        jLabel14.setText("* Nº Celular:");

        jLabel16.setText("Pais");

        jCbxPais.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCbxPaisActionPerformed(evt);
            }
        });

        jLabel17.setText("Provincia");

        jCbxProvincia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCbxProvinciaActionPerformed(evt);
            }
        });

        jLabel19.setText("Ciudad");

        jLblFoto.setBackground(new java.awt.Color(255, 255, 204));

        jLabel22.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel22.setText("Detalle");

        jBtnFoto.setBackground(new java.awt.Color(255, 255, 255));
        jBtnFoto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/picture.png"))); // NOI18N
        jBtnFoto.setText("FOTO DEL CLIENTE");
        jBtnFoto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnFotoActionPerformed(evt);
            }
        });

        jLabel23.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel23.setText("Codigo:");

        jLabel25.setText("* E - Mail:");

        jLabel15.setText("*Direccion");

        jLabel9.setForeground(new java.awt.Color(255, 0, 0));

        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/tango-clear.png"))); // NOI18N
        jButton9.setText("LIMPIAR CAMPOS");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jLabel1.setText("Apellido");

        jLabel2.setText("Cargo");

        javax.swing.GroupLayout jPanelTransparente6Layout = new javax.swing.GroupLayout(jPanelTransparente6);
        jPanelTransparente6.setLayout(jPanelTransparente6Layout);
        jPanelTransparente6Layout.setHorizontalGroup(
            jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                        .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                                .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                                        .addComponent(jLabel23)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE))
                                    .addComponent(jLabel15)
                                    .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                                        .addComponent(jLabel10)
                                        .addGap(6, 6, 6)
                                        .addComponent(jTxtTelefono, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE))
                                    .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                                        .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel12)
                                            .addComponent(jLabel13)
                                            .addComponent(jLabel1))
                                        .addGap(17, 17, 17)
                                        .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jTxtNombre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                                            .addComponent(jTxtApellido, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                                            .addComponent(jTcedula, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                                            .addComponent(jTxDireccion, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)))
                                    .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                                        .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel14)
                                            .addComponent(jLabel25)
                                            .addComponent(jLabel2)
                                            .addComponent(jLabel16))
                                        .addGap(6, 6, 6)
                                        .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jCbxPais, 0, 256, Short.MAX_VALUE)
                                            .addComponent(jTxtMail, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                                            .addComponent(jTxtCelular, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                                            .addComponent(jCBCargo, 0, 256, Short.MAX_VALUE)
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelTransparente6Layout.createSequentialGroup()
                                                .addComponent(jCbxProvincia, 0, 255, Short.MAX_VALUE)
                                                .addGap(1, 1, 1))
                                            .addComponent(jCBCiudad, javax.swing.GroupLayout.Alignment.TRAILING, 0, 256, Short.MAX_VALUE))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jBtnFoto, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel22)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLblFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, 641, Short.MAX_VALUE))
                        .addContainerGap())
                    .addComponent(jLabel17)
                    .addComponent(jLabel19)))
        );
        jPanelTransparente6Layout.setVerticalGroup(
            jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(1, 1, 1)
                .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jTxtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                        .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                                .addComponent(jLabel22)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane1))
                            .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1)
                                    .addComponent(jTxtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel12)
                                    .addComponent(jTcedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel15)
                                    .addComponent(jTxDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel10)
                                    .addComponent(jTxtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(11, 11, 11)
                                .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel14)
                                    .addComponent(jTxtCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                                .addComponent(jBtnFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18))
                            .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                                .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jTxtMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel25))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel2)
                                    .addComponent(jCBCargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(6, 6, 6)))
                        .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel16)
                            .addComponent(jCbxPais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel17)
                            .addComponent(jCbxProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCBCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel19)))
                    .addComponent(jLblFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jBSalir1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Desktop 2.png"))); // NOI18N
        jBSalir1.setText("SALIR");
        jBSalir1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSalir1ActionPerformed(evt);
            }
        });

        jBActualizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/refresh.png"))); // NOI18N
        jBActualizar.setText("ACTUALIZAR");
        jBActualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBActualizarActionPerformed(evt);
            }
        });

        ListSelectionModel ls =  jTable1.getSelectionModel();
        ls.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                try{
                    if(e.getValueIsAdjusting())return;
                    ListSelectionModel lsss=(ListSelectionModel )e.getSource();
                    if(lsss.isSelectionEmpty()){
                    }else{
                        condicion=true;
                    }
                }catch(Exception z){
                }
            }
        });
        jBModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/edit.png"))); // NOI18N
        jBModificar.setText("MODIFICAR");
        jBModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBModificarActionPerformed(evt);
            }
        });

        ListSelectionModel lssms =  jTable1.getSelectionModel();
        lssms.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                try{
                    if(e.getValueIsAdjusting())return;
                    ListSelectionModel lss=(ListSelectionModel )e.getSource();
                    if(lss.isSelectionEmpty()){
                    }else{
                        condicion=true;
                    }
                }catch(Exception z){
                }
            }
        });
        jBEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/stop.png"))); // NOI18N
        jBEliminar.setText("ELIMINAR");
        jBEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEliminarActionPerformed(evt);
            }
        });

        jBRegistrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Floppy.png"))); // NOI18N
        jBRegistrar.setText("REGISTRAR");
        jBRegistrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBRegistrarActionPerformed(evt);
            }
        });

        JBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/search.png"))); // NOI18N
        JBuscar.setText("BUSCAR");
        JBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBuscarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelTransparente7Layout = new javax.swing.GroupLayout(jPanelTransparente7);
        jPanelTransparente7.setLayout(jPanelTransparente7Layout);
        jPanelTransparente7Layout.setHorizontalGroup(
            jPanelTransparente7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTransparente7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JBuscar, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                    .addComponent(jBActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBModificar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                    .addComponent(jBEliminar, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                    .addComponent(jBRegistrar, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                    .addComponent(jBSalir1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelTransparente7Layout.setVerticalGroup(
            jPanelTransparente7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(JBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jBModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jBEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jBRegistrar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jBSalir1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(40, Short.MAX_VALUE))
        );

        jTable1.setModel(dtm);
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanelTransparente6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanelTransparente7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 886, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanelTransparente7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelTransparente6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jMenu1.setText("Operaciones");
        jMenu1.add(jSeparator1);

        jMenuItem8.setText("Salir");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem8);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edicion");

        jMenuItem1.setText("Copiar");
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        // Salir
        this.dispose();
}//GEN-LAST:event_jMenuItem8ActionPerformed

    private void jTxtNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxtNombreActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jTxtNombreActionPerformed

    private void jCbxPaisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCbxPaisActionPerformed
    // Pais
        jCbxProvincia.removeAllItems();
        jCBCiudad.removeAllItems();
        if(jCbxPais.getSelectedIndex()!=0){
            String nombre = ""+jCbxPais.getSelectedItem();
            Pais ps = Mu.Consultar(nombre);

            for(int x=0; x<ps.getProvincia().size();x++){
                  jCbxProvincia.addItem(ps.getProvincia().get(x).getNombre());

        }

       }
}//GEN-LAST:event_jCbxPaisActionPerformed

    private void jBtnFotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnFotoActionPerformed
        JFileChooser dlg = new JFileChooser();
        //Abre la ventana de dialogo
        int option = dlg.showOpenDialog(this);
        //Si hace click en el boton abrir del dialogo
        if(option==JFileChooser.APPROVE_OPTION) {
            //Obtiene nombre del archivo seleccionado
            String file = dlg.getSelectedFile().getPath();
            jLblFoto.setIcon(new ImageIcon(file));
            //Modificando la imagen
            ImageIcon icon = new ImageIcon(file);
            //Se extrae la imagen del icono
            Image img = icon.getImage();
            //Se modifica su tamaño
            Image newimg = img.getScaledInstance(140,170,java.awt.Image.SCALE_SMOOTH);
            //SE GENERA EL IMAGE ICON CON LA NUEVA IMAGEN
            ImageIcon newIcon = new ImageIcon(newimg);
            //Se coloca el nuevo icono modificado
            jLblFoto.setIcon(newIcon);
            //Se cambia el tamaño de la etiqueta
            jLblFoto.setSize(470,290);
        }
}//GEN-LAST:event_jBtnFotoActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        // LimpiarCampos

}//GEN-LAST:event_jButton9ActionPerformed

    private void jBSalir1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSalir1ActionPerformed
        // Cerramos esta ventana
        this.dispose();
}//GEN-LAST:event_jBSalir1ActionPerformed

    private void jBActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBActualizarActionPerformed
        // Actualizar ó cancelar
        this.Actualizar();

}//GEN-LAST:event_jBActualizarActionPerformed

    private void jBModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBModificarActionPerformed
        //Modificar Cliente


    }//GEN-LAST:event_jBModificarActionPerformed

    private void jBEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBEliminarActionPerformed
// Eliminar
        Empleado e = new Empleado();
        if(condicion==true){
            int question = JOptionPane.showConfirmDialog(null,"¿Seguro que desea"
                    + " eliminar este Empleado?","Informacion",JOptionPane.YES_NO_OPTION);
            if(question==0){
                  e = Me.getListaEmpleado().get(jTable1.getSelectedRow());
                  int posicion = jTable1.getSelectedRow();
                  dtm.removeRow(posicion);
                  Me.Eliminar(e.getCedula());
            }else{
                JOptionPane.showMessageDialog(null, "Peticion ca"
                        + "ncelada","Informacion",JOptionPane.INFORMATION_MESSAGE);
            }
        }else{
                String ced = JOptionPane.showInputDialog("Digite Cedula del Empleado a buscar");

                if(ced!=null){
                       e = this.Me.Consultar(ced);

                        if(e.getNombre().equals("")){
                            JOptionPane.showMessageDialog(null, "Este Empleado no existe");
                        } else {
                            int posicion = Me.Posicion(e.getCodigo()+"");
                            Me.Eliminar(e.getCedula());
                            this.Actualizar();
                        }
                 }
        }
        this.condicion = false;

    }//GEN-LAST:event_jBEliminarActionPerformed

    private void jBRegistrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBRegistrarActionPerformed
        //Registrar
         if(jBRegistrar.getText().equals("GUARDAR")){
            this.Registrar();
        }else{
            this.ActivarCampos();
            this.jLabel9.setVisible(true);
            this.jBRegistrar.setText("GUARDAR");
            this.jBActualizar.setText("CANCELAR");
            ImageIcon[] img_Btns = new ImageIcon[8];
            img_Btns[0] = new ImageIcon(getClass().getResource("/Imagenes/"
                    + "stop_alt.png"));
            jBActualizar.setIcon(img_Btns[0]);
            this.Limpiar_Entradas();
            this.jLabel9.setText(this.Me.GenerarCodigo()+"");
        }


    }//GEN-LAST:event_jBRegistrarActionPerformed

    private void JBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBuscarActionPerformed
        // Buscar proveedor especificamente


}//GEN-LAST:event_JBuscarActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked

        int posicionn=this.jTable1.getSelectedRow();
        Empleado e = new Empleado();
        e = Me.getListaEmpleado().get(posicionn);
        this.mostrar(e);
    }//GEN-LAST:event_jTable1MouseClicked

    private void jCbxProvinciaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCbxProvinciaActionPerformed
            // Ciudades
          if(jCbxPais.getSelectedIndex()!=0){
            String nombre = ""+jCbxPais.getSelectedItem();
            String nombreprovinia = jCbxProvincia.getSelectedItem()+"";
            Pais ps = Mu.Consultar(nombre);
            Provincia pro = ps.getProvincia().get(this.Posicion(nombreprovinia, ps.getProvincia()));

            for(int x=0;x<pro.getCiudad().size();x++){
               Ciudad c =(Ciudad) pro.getCiudad().get(x);
               jCBCiudad.addItem(c.getNombre());
            }

        }
    }//GEN-LAST:event_jCbxProvinciaActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VistaEmpleado().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JBuscar;
    private javax.swing.JButton jBActualizar;
    private javax.swing.JButton jBEliminar;
    private javax.swing.JButton jBModificar;
    private javax.swing.JButton jBRegistrar;
    private javax.swing.JButton jBSalir1;
    private javax.swing.JButton jBtnFoto;
    private javax.swing.JButton jButton9;
    private javax.swing.JComboBox jCBCargo;
    private javax.swing.JComboBox jCBCiudad;
    private javax.swing.JComboBox jCbxPais;
    private javax.swing.JComboBox jCbxProvincia;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLblFoto;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JPanel jPanel3;
    private Imagenes.JPanelTransparente jPanelTransparente6;
    private Imagenes.JPanelTransparente jPanelTransparente7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTcedula;
    private javax.swing.JTextField jTxDireccion;
    private javax.swing.JTextArea jTxaObs;
    private javax.swing.JTextField jTxtApellido;
    private javax.swing.JTextField jTxtCelular;
    private javax.swing.JTextField jTxtMail;
    private javax.swing.JTextField jTxtNombre;
    private javax.swing.JTextField jTxtTelefono;
    // End of variables declaration//GEN-END:variables

     

    private void mostrar(Empleado cl) {

        this.jTxtNombre.setText(cl.getNombre());
        this.jTxtApellido.setText(cl.getApellido());
        this.jTcedula.setText(cl.getCedula()+"");
        this.jTxDireccion.setText(cl.getDireccion());
        this.jTxtTelefono.setText(cl.getTelefono());
        this.jTxtMail.setText(cl.getEmail());
        this.jTxtCelular.setText(cl.getCelular());
        this.jLblFoto.setIcon(cl.getFoto());
        this.jLabel9.setText(cl.getCodigo());
        this.jTxaObs.setText(cl.getDetalle());
        
    }

    private void BorrarCampos() {

        this.jTxtNombre.setText("");
        this.jTxtTelefono.setText("");
        this.jTxtMail.setText("");
        this.jTxDireccion.setText("");
        this.jTxtCelular.setText("");
        this.jTxaObs.setText("");
        this.jLblFoto.setIcon(null);
        this.jLabel9.setText("");
        this.jTxtApellido.setText("");
        this.jTcedula.setText("");
    }


    private void ActivarCampos() {

        this.jTxtNombre.setEditable(true);
        this.jTxtTelefono.setEditable(true);
        this.jTxtMail.setEditable(true);
        this.jTxDireccion.setEditable(true);
        this.jTxtCelular.setEditable(true);
        this.jTxaObs.setEditable(true);
        this.jBtnFoto.setEnabled(true);
        this.jTxtApellido.setEditable(true);
        this.jTcedula.setEditable(true);
    }

    private void DesactivarCampos() {
        this.jTxtNombre.setEditable(false);
        this.jTxtTelefono.setEditable(false);
        this.jTxtMail.setEditable(false);
        this.jTxDireccion.setEditable(false);
        this.jTxtCelular.setEditable(false);
        this.jTxaObs.setEditable(false);
        this.jTcedula.setEditable(false);
        this.jTxtApellido.setEditable(false);
        this.jBtnFoto.setEnabled(false);
    }

    

    private void Registrar() {

        Empleado c = new Empleado();
        c.setNombre(jTxtNombre.getText());
        c.setApellido(jTxtApellido.getText());
        c.setDireccion(jTcedula.getText());
        c.setCedula(jTxDireccion.getText());
        c.setTelefono(jTxtTelefono.getText());
        c.setEmail(jTxtMail.getText());
        c.setCelular(jTxtCelular.getText());
        if(jLblFoto.getIcon()!=null){
            c.setFoto(jLblFoto.getIcon());
        }
        c.setDetalle(jTxaObs.getText());
        c.setCargo(Mc.Consultar(jCBCargo.getSelectedItem().toString()));
        c.setUbicacion(new Ubicacion(jCbxPais.getSelectedItem().toString(), jCbxProvincia.getSelectedItem().toString(), jCBCiudad.getSelectedItem().toString()));
        Me.Registrar(c);
        this.Actualizar();

    }

    public void Actualizar(){

        this.dispose();
        VistaEmpleado Ve = new VistaEmpleado(Me,Mc,Mu);
        Ve.setLocationRelativeTo(null);
        Ve.setVisible(true);

    }

    private void Limpiar_Entradas() {

        jLabel9.setText("");
        jTxtNombre.setText("");
        jTxtApellido.setText("");
        jTcedula.setText("");
        jTxDireccion.setText("");
        jTxtTelefono.setText("");
        jTxtCelular.setText("");
        jTxtMail.setText("");
        jLblFoto.setIcon(null);
        jTxtNombre.requestFocus();


    }

    private void TablaPrincipal() {
        dtm.addColumn("Nombre");
        dtm.addColumn("Apellido");
        dtm.addColumn("Identificación");
        dtm.addColumn("Direccion");
        dtm.addColumn("Telefono");
        dtm.addColumn("Email");
        dtm.addColumn("Cargo");
        dtm.addColumn("Salario");

         for(int a=0;a<Me.getListaEmpleado().size();a++){
            Vector<String> vc=new Vector<String>();
            e = Me.getListaEmpleado().get(a);
            vc.add(e.getNombre());
            vc.add(e.getApellido());
            vc.add(""+e.getCedula());
            vc.add(e.getDireccion());
            vc.add(e.getTelefono());
            vc.add(e.getEmail());
            vc.add(e.getCargo().getNombre());
            vc.add(e.getCargo().getSalario()+"");
            dtm.addRow(vc);
        }
    }

    private void JcomboCargos() {
        for(int x=0;x<Mc.getListaCargo().size();x++){
            Cargo c = Mc.getListaCargo().get(x);
            jCBCargo.addItem(c.getNombre());
        }
    }

    private void jComboPais() {
        jCbxPais.addItem("---Seleccion---");
        for(int x=0;x<Mu.getPaises().size();x++){
            jCbxPais.addItem(Mu.getPaises().get(x).getNombre());
        }
    }

        public int Posicion(String nombre,List<Provincia> pro){
            Provincia p;
          Iterator itc=pro.iterator();
          int pos=-1;
          int ind=-1;
         while(itc.hasNext()){
             p = (Provincia)itc.next();
            if(p.getNombre().equals(nombre)){
                ind=ind+1;
                 pos=ind;
            }else{
                ind=ind+1;
            }
         }
          return pos;
    }
   
}
